package oleg.log;

/**
 * Copyright 2009 Oleg Frenkel
 *
 * This file is part of PerfectSearch.
 *
 * PerfectSearch is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PerfectSearch is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PerfectSearch.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Vector;

import oleg.C;

public class Logger
{
  static private final int MAX_SIZE = 100;

  static private final Vector buf = new Vector();

  private Logger() {}

  static public void log(String str) {
    if (!C.DEBUG) {
      return;
    }

    Runtime rt = Runtime.getRuntime();
    double freeMem = rt.freeMemory();
    double totalMem = rt.totalMemory();
    if (freeMem/totalMem < .2) {
      buf.removeAllElements();
    } else if (buf.size() > MAX_SIZE) {
      buf.removeElementAt(0);
    }

    buf.addElement(str);
  }

  static public Vector getLog() {
    return buf;
  }
}